package com.wbt.jdk8.function;

import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class TestFunction {
    private final static Map<String, Object> beanDefinitionMap = new ConcurrentHashMap<>(256);
    private static Set<String> manualSingletonNames = new LinkedHashSet<>(16);

    public static void main(String[] args) {
        consumerMethod("aa",new Object());
    }


    public static void consumerMethod(String name, Object singletonObject){
        consumerDoMethod(set -> set.add(name),set -> !beanDefinitionMap.containsKey(name));

        System.out.println("beanDefinitionMap:" + beanDefinitionMap.size());
        System.out.println("manualSingletonNames:" + manualSingletonNames);

    }

    public static void consumerDoMethod(Consumer<Set<String>> action, Predicate<Set<String>> condition){

        if (condition.test(manualSingletonNames)) {
            System.out.println("============================");
            Set<String> updatedSingletons = new LinkedHashSet<>(manualSingletonNames);
            action.accept(updatedSingletons);
            manualSingletonNames = updatedSingletons;
        }else {
            System.out.println("----------------------------");
        }
    }
}
